/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
 var findMode = function(root) {
    let pre = null
    let count = 0,maxCount = 1
    let res = []
    const travelTree = function(cur){
      if(cur === null){
        return 
      }
      travelTree(cur.left)
      if(pre && (pre.val === cur.val)){
        count++
      }else{
        count = 1
      }
      pre = cur
      if(count === maxCount){
        res.push(cur.val)
      }
      if(count > maxCount){
        res = []
        maxCount = 1
        res.push(cur.val)
      }
      travelTree(cur.right)
    }
    travelTree(root)
    return res
};